package com.vict.config;

import cn.hutool.setting.Setting;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.io.File;

@Slf4j
@Component
public class SettingConfig {

    public static File configFile;
    public static Setting setting;


    public void init(){
        log.info("初始化配置文件");
        configFile = loadConfigTxt();

        setting = new Setting(configFile.getAbsolutePath());

        // 初始化banKuaiMoneyCron
        // String banKuaiMoneyCron = setting.getStr(key_banKuaiMoneyCron);
        // if(banKuaiMoneyCron == null || banKuaiMoneyCron.trim().equals("")){
        //     banKuaiMoneyCron = Common.banKuaiMoneyCron;
        //     setting.set(key_banKuaiMoneyCron, banKuaiMoneyCron);
        //     setting.store();
        // }

        log.info("初始化配置完毕");
    }


    /** 加载本地配置文件 */
    public File loadConfigTxt() {
        try{
            if(Init.isInit){ // 已经初始化过
                File file = new File("config.setting");
                return file;
            }else{
                File file = new File("config.setting");
                if(file.exists()){
                    file.delete();
                }
                file.createNewFile();
                return file;
            }
        }catch(Exception e){
            log.error("", e);
        }
        throw new RuntimeException("加载本地配置文件异常");
    }
}
